package com.sh.哈希;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class 两数和 {
    public static void main(String[] args) {
        int[] nums = new int[]{2, 7, 11, 15};
        int target = 9;
        int[] ints = twoSum(nums, target);

    }


    public static int[] twoSum(int[] nums, int target) {
//        Map<Integer, Integer> hashMap = new HashMap<>();
//        for (int i = 0; i < nums.length; i++) {
//            int temp = target - nums[i];
//            if (hashMap.containsKey(temp)) {
//                return new int[]{hashMap.get(temp), i};
//            }
//            hashMap.put(nums[i], i);
//        }
//        return new int[0];
        int[] ints = new int[2];
        for (int i = 0; i < nums.length; i++) {
            int temp = target-nums[i];
            for (int j = i+1; j < nums.length; j++) {
                if (temp==nums[j]){
                    return new int[]{i,j};
                }
            }

        }
        return  ints;
    }
}

